import static org.junit.Assert.assertEquals;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.junit.After;
import org.junit.Test;


public class TestCache {
	CacheClass<Integer, Integer> cC=new CacheClass<Integer,Integer>();
	ExecutorService executor=Executors.newFixedThreadPool(4);
	Random random=new Random();
	int counter=0;
	int truecounter=0;
	
	@Test
	public void test() {
		for (int i = 0; i < 1000000; i++) {
			executor.submit(new Runnable(){
				public void run(){
					
					for (int j = 0; j < 1000; j++) {
						int key=random.nextInt(20);
						if (cC.collect(key)){
							counter++;
							if (key==cC.get(key)) truecounter++;
						}else{
							cC.put(key, key);
						}
					}
					
				}
			});
			//System.out.println(i);
		}
	}
	@After
	public void checking(){
		executor.shutdown();
		System.out.println(counter-truecounter);
		assertEquals(counter,truecounter);
	}
}
